﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;

namespace ProjectBuilder
{
    [DbTable("phpdoc_inherited_constants")]
    class InheritedConstants : BaseRefObject
    {
        [DbField("class_id")]
        public long? ClassId { get; set; }

        [DbField("parent_id")]
        public string Parent { get; set; }

        [DbField("distance")]
        public int Distance { get; set; }

        [DbField("constant_id")]
        public long? ConstantId { get; set; }

        public InheritedConstants(ProjectBuilder.PhpDocTypes.InheritedVariable ic,long? classId) 
        {
            ClassId = classId;
            Parent = ic.Class;
            Distance = ic.Distance;
            var parentId = Class.getIdByName(Parent);
            var cmd = new MySqlCommand();
            cmd.CommandText = "SELECT `id` FROM `phpdoc_const` WHERE `name` = '" + ic.Name + "' AND `class_id` = " + parentId;
            cmd.CommandType = CommandType.Text;
            cmd.Connection = Globals.Connection;
            var constantId = cmd.ExecuteScalar();
            ConstantId = -1;
            if (constantId != null)
                ConstantId = long.Parse(constantId.ToString());
        }
    }
}
